// 访问类型修饰符  private、protected和public
{
  class Person {
    public name: string
    public sayHello() {
      console.log(this.name + ' say Hello')
    }
  }

  const person = new Person()
  person.name = 'jspang.com'
  person.sayHello()
  console.log(person.name)
}

{
  class Person {
    private name: string // private 访问属性的意思是，只允许再类的内部被调用，外部不允许调用
    public sayHello() {
      console.log(this.name + 'say Hello') //此处不报错
    }
  }
  //-------以下属于类的外部--------
  const person = new Person()
  // person.name = 'jspang.com'    //此处报错
  person.sayHello()
  // console.log(person.name)  //此处报错
}

{
  class Person {
    protected name: string // protected 允许在类内及继承的子类中使用
    public sayHello() {
      console.log(this.name + 'say Hello') //此处不报错
    }
  }

  class Teacher extends Person {
    public sayBye() {
      this.name
    }
  }
}
{
  class Person {
    public name: string
    constructor(name: string) {
      this.name = name
    }
  }

  const person = new Person('jspang')
  console.log(person.name)
}
{
  // 上面类的简写方式
  class Person {
    constructor(public name: string) {}
  }

  const person = new Person('jspang')
  console.log(person.name)
}
